home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 6
/
The Arsenal Files 6 (Arsenal Computer).ISO
/
prg_casm
/
struc.zip
/
STRUC.ASM
< prev
Wrap
Assembly Source File
|
1996-02-02
|
5KB
|
128 lines
; I'll be using the extended registers, so ".386" is required here. I'm
; using simplified directives here. However, there is no reason why that I
; can't declare my own segments. I will probably give a sample of that
; in a future upload or an appended version of this upload.
.386
;-----I'll be accessing extended memory while in protected mode. In that
; mode, memory is like one of those highways across the western U.S.
; deserts. Using the "C" calling convention eliminates the need for the
; preceding underscores.
.model flat, c
;-----The assembler structure which makes it easy to manipulate data between
; the C++ module and here
mystruct struc
ascii_char db ?
unsigned_char db ?
short dw ?
unsigned_short dw ?
long dd ?
unsigned_long dd ?
string db 13, 10, "This is the string from the .asm routine", 0
mystruct ends
;----- This will be the data segment. It is of course not segmented the
; same as in real mode, but is defined that way.
.data
struct_1 mystruct <,,,,,>
esp_save dd ?
ss_save dw ?
ebp_save dd ?
struct_ptr dd ?
;----------------------------------------
;----- Here is the declaration of the section where the code will begin.
; variables can go here as well, however it is not normal, or keeping
; in tradition to write to the code area (modify variables) while
; operating in protected mode.
.code
;----- Since this routine will be "called" from the C++ module, it must of
; course be made "public"
public fill_struct
;----- all procedures in protected mode are of type "near". Something that
; i've noticed when compiling using Power Pack is that "near" actually
; has to be declared here. Whereas usually it will default to "near"
; here as long as "near" is declared at the end of the procedure.
fill_struct proc near
;----- This is the argument that was passed to here from the C++ module
ARG the_struct:dword
;----- I have the most success saving and repositioning reference to the
; stack using this method. I often prefer to define a separate stack
; within my assembler module. This lays the ground-work to do that.
; I'll be showing how easy it is to do that, at a later date.
mov ebp_save, ebp
mov ss_save, ss
mov esp_save, esp
mov ebp, esp
;----- This will load the EBX register with the address of the structure
; within the C++ module. This also makes it quite convenient to access
; character sequences of structured type. I'll also save this argument
; just out of habit, so I don't have to worry about finding it on the
; stack if I need it later.
mov ebx, [the_struct]
mov [struct_ptr], ebx
;----- The following code will use the offset values from my assembler
; routine to load values into the structure within the C++ module.
mov [struct_1.unsigned_char], 255
mov cl, [struct_1.unsigned_char]
;----- Here is the actual loading of the structure within the C++ module.
; I can also, first fill my structure here, with the data I desire,
; and then send a copy of that data to the C++ module. If you've been
; following the code, you may have noticed, setting up to do that was
; the little maneuver that I did in the two lines above. It would
; also be perfectly fine to load default values within my structure,
; as is more commonly done.
mov [ebx].ascii_char, -'~'
mov [ebx].unsigned_char, cl
mov [ebx].short, -32767
mov [ebx].unsigned_short, 65535
mov [ebx].long, -2147483647
mov [ebx].unsigned_long, 4294967295
;----- This is the code used to copy our string over to the allocated
; array within the C++ module. Note that I've terminated the array
; with 0, since I believe that to be what the C++ print function will
; look for as a terminator. Also note that although the value in CX
; can exceed the actual length of the string from this module, it
; -MUST NOT- exceed the size of the allocated array within the C++
; module. Also note that even though I'm only moving a byte at a
; time here, there is no reason, one cannot move 32 bits at a time.
mov edx, offset struct_1.string
mov cx, 54
cld
repeat:
mov al, [edx]
mov [ebx].string, al
inc edx
inc bx
dec cx
cmp cx, 0
jne repeat
;----- Now we'll return the saved stack type registers.
mov esp, esp_save
mov ss, ss_save
mov ebp, ebp_save
ret
fill_struct endp
;----- That's all there is to it. Pretty easy don't you think?
; Now.... let's give Borland a round of applause for their
; Power Pack product!
end